... my $text; my $match = 0; my $regex = qr/$ARGV[1]/; { local $/; # enable "slurp" mode $text = <$fh>; # read whole file } while ($text =~ /$regex/gms) { print "Match found\n"; $match = 1; } print "No matches found\n" unless $match;