in reply to extract numerical string from a bunch of words

There are several ways to approach this, depending on what parts of your input are unlikely to change (ie, what you can reliably anchor off of). For example, is it always the first numeric field per line? Is the numeric field always seven digits? Does it always come after 'Change'? Does it always come before 'on' followed by a date?

Let's say it's always the first numeric field following the word "Change ". You could match like this:

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;

But really, I think we would need to know about your input format before we could be sure we're giving you a good answer. Do you slurp it all in at once? Do you read it line by line? ...lots of possibilities that would change the answer in various ways.

Update: Oh, you want a one-liner. Didn't see that before.

perl -ne "m/^Change\s(\d+)\s/ && print $1, qq/\n/;"

Dave