if ( /1tally\s\s(\d+)\s+nps\s=/i ) { foreach ( 1 .. 5 ) { my $junk = ; } next; } #### while () { last if /^\s+energy\n$/; } while () { last if /^\s+total\s+\d/; /\s\s\s(\d+)\.(\d+)(\D+)(\d+)\s\s\s(\d+)\.(\d+)(\D+)(\d+)\s(\d+)\.(\d+)/ or warn "This line did not match the pattern: '$_'" and next; $energy_value = $1.$dot.$2.$3.$4; #... }