foreach my $file (@files) { open my $fh, '<', $file or warn "Coudn't open $file \n"; while (<$fh>) { if (/(printf.*\;)/sm) { my $buffer = $1; push @printfs, $buffer; } } close $fh; }