#!/usr/bin/perl -w use strict; use 5.016; # 1088912 my @args=@ARGV; find_string(@args); # mod of OP's original: sub find_string { my $file = shift; my $string = shift; open my $fh, '<', $file; while ( <$fh> ) { if ($_ =~ /\Q$string/) { warn "Test result is FAIL (i.e. $string is present in $file)"; } else { if ($_ !~ /\Q$string/) { say "\t Did NOT find $string in $_"; } } } }