>perl -wMstrict -le "my $pre = qr{ \A | \s }xms; my $post = qr{ \s | \z }xms; my $str = q{foo='123' barfoo='987' bar='555'}; for my $user_supplied (@ARGV) { my $rx = qr{ $pre \Q$user_supplied\E $post }xms; $str =~ m{ ($rx) }xms; print qq{[$user_supplied] matches }, $1 ? qq{[$1]} : q{nothing}; } " foo='123' bar='555' barfoo='987' foo='987' [foo='123'] matches [foo='123' ] [bar='555'] matches [ bar='555'] [barfoo='987'] matches [ barfoo='987' ] [foo='987'] matches nothing