use strict; open my $fh, "file.txt" or die "Error opening file.txt: $!"; print grep /pattern/, <$fh>;