foreach my $file (@ARGV) { open my $fh, $file or warn("Cannot open file $file: $!\n"), next; my $header = <$fh>; #process header while (<$fh>) { # process file } }