use strict; use warnings; my $input = "input.txt"; open my $IN, "<", $input or die "cannot open $input $!"; my $output = "output.txt"; open my $OUT, ">", $output or die "cannot open $output $!"; while (my $line = <$IN>) { chomp $line; # remove newline character from end of line if ($line =~ /INTERPOLATED HYDROGRAPH AT (\w+)$/){ print $OUT $1; $line = <$IN> for 1..6; # skip 5 lines my $val2 = (split / /, $line)[1]; # get the second column print $OUT " $val2"; $line = <$IN>for 1..2; # skip one line chomp $line; my $val3 = (split / /, $line)[-1]; # get the last column print $OUT " $val3\n"; } }