in reply to Regexp problem: filtering

You can test for the start of the string with \A, so m/\Afoo/ checks if $_ starts with foo.

You can match the end of the string witz \z, so if you have want to check if a string ends with bar, use m/bar\z/.

If you want to exclude a string from your search, you can use the negative lookahead: m/^(?!.*foo).*bar/ matches a string that contains a bar but no foo.

You can put it all together: to match a string that begins with foo, ends with bar and doesn't contain baz you can use this regex: m/\Afoo(?!.*baz).*bar\z/s

Most of the time it's easier to put all that into different regexes:

if (m/^foo/ && m/bar$/ && !m/baz/){ ... }

See perlre for details