Q:

`/s` for multiline for variable regular expression `qr//`

I'm trying to match and extract the first (path like) word and the very last word in a multiline string (text = shell prompt + command + output). I have a working regular expression
perl -le 'print "$1/$2" if "~/src\nfind\nboards.txt" =~ m`([/~]\S+).*?(\S+)\s*$`s'
# returns expected ~/src/boards.txt

(https://regex101.com/r/uB4kN1/4 for nicer illustration)
But I run into problems when I try to use a variable regular expression.
echo '([/~]\S+).*?(\S+)\s*$' | 
  perl -lne '$reg=qr/$_/; 
             print "$1/$2" if "~/src\nfind\nboards.txt" =~ /$reg/s';

A:

the /s single-string option should be provided at qr// not in the =~ // comparison 
echo '([/~]\S+).*?(\S+)\s*$' | 
 perl -lne '$reg=qr/$_/s;  # < HERE
            print "$1/$2" 
              if "~/src\nfind\nboards.txt" =~ /$reg/';
            #                               NOT HERE^

