in reply to avoiding a particular character or set of characters

You might try something more like this:

if ($line =~ /^\s*public(*.);\s*$/) { # do something }

The use of anchors (^ and $) at the beginning and end of your pattern will ensure that nothing (except some optional space characters) will appear before the 'public' or after the ';'. You may be able to adapt this to your needs.


No good deed goes unpunished. -- (attributed to) Oscar Wilde