http://www.perlmonks.org?node_id=11159753


in reply to Regexp match start or end

But is there a way of combining those two regexps into just one?

I think (untested):
 =~ /^perfect|perfect$/i will return true if and only if "perfect"(case-insensitive) appears at either the beginning or the end (or both).
 !~ /^perfect|perfect$/i will return true if and only if "perfect"(case-insensitive) appears neither at the beginning nor the end.

Update: As LanX has noted, beginnings such as "perfection" and endings such as "imperfect" will also be matched.

Cheers,
Rob