my @numbers; # Assuming we're reading from a file line by line... while( <> ) { chomp; next unless length $_; if( m/^Change\s(\d+)\s/ ) { push @numbers, $1; } } print "$_\n" for @numbers;