my $contents =<## use strict; use warnings; my $contents = " #################### # GEOGRAPHY CONFIG # #################### environment.type = eu deployment.type = au"; if ( $contents !~ /deployment.type = (\w+)/gm) { print "ERROR: deployment.type not found in contents\n"; } else { print "deployment.type matched\n"; } $contents =~ /./g; # <-- this search passes end of string, and resets if ( $contents !~ /environment.type = (\w+)/gm ) { print "ERROR: environment.type not found in contents\n"; } else { print "environment.type matched\n"; } __END__ qwurx [shmem] 01:36 ~ > perl au.pl deployment.type matched environment.type matched