use Tie::File; my( $file_name, $arg1, $arg2 ) = @ARGV; # open the file with tie tie my @file_lines, 'Tie::File', $file_name or die; # delete the first line shift @file_lines; # filter out lines containing 'sandwich' @file_lines = grep !/^$arg1,$arg2,/, @file_lines; # close the file with untie. # IMPORTANT: always untie when you are done! untie @file_lines or die "$!";