{ local $/ = ";"; # local means perl will restore the value of $/ at the end of the block # and the default behaviour when reading a file for my $file (@files) { # Note the $!, which contains the reason for the opening failure open my $fh, '<', $file or warn "Coudn't open $file: $!\n"; while (<$fh>) # will stop at each ";", so read instruction by instruction { push @printfs, $1 if /(printf.*);/; } } }