use strict; use warnings; print "\n"; scalar @ARGV == 2 or die "USAGE: perl $0 \n"; open(my $fh, '<', $ARGV[0]) or die "Unable to open file '$ARGV[0]' for reading: $!"; my $match = 0; my $regex = qr/$ARGV[1]/; my @lines = <$fh>; # read whole file foreach (0 .. $#lines) { if ($lines[$_] =~ /$regex/) { printf "Match found on line %d\n", ($_ + 1); $match = 1; } } print "No matches found\n" unless $match;