open RAN, "f03_20859_04aug08RANmri_block2.log" or die "Unable to open file!"; open NEW, ">>Out.txt" or die "Unable to open file for output!"; open AVG, "Avg.txt" or die "Unable to open file for averaging!"; while ( my $text = ) { if ( $text =~ /\bResponse\b/ ) { @response = split( /\s/, $text ); print NEW $text, "\n"; } print AVG $response[4]; } close NEW; close RAN; close AVG;