in reply to extracting from text

I'd save an array of values under the hash key and sort afterwards (looks not very elegant but works):

... my @stuff= ( 'hi: 65 abcdefghijklmnopqrst 85', 'bye: 12 bcdefghijklmnopqrstu 32' +, 'hi: 86 sagfsdgsgwsehbbdgops 106', 'bye: 33 afasdfdfafasaafadfad 53 +'); my %cnt; /(\w+)\D+(\d+)\s+\w+\s+(\d+)/ && push @{$cnt{$1}},($2,$3) for @stuff; @$_ = sort { $a <=> $b } @$_ for values %cnt; print map "\$${_}_from=$cnt{$_}[0] and \$${_}_to=$cnt{$_}[-1]\n", keys %cnt; ...

displays here:

$hi_from=65 and $hi_to=106 $bye_from=12 and $bye_to=53

Addendum: after reading the other posts I'd think one could also beam the values into predefined my-Variables by an eval. Im not sure if (w/error handling added) this would be that bad:

use strict; # go for it use warnings; my @stuff= ( 'hi: 65 abcdefghijklmnopqrst 85', 'bye: 12 bcdefghijklmnopqrstu 32' +, 'hi: 86 sagfsdgsgwsehbbdgops 106', 'bye: 33 afasdfdfafasaafadfad 53 +'); my %cnt; /(\w+)\D+(\d+)\s+\w+\s+(\d+)/ && push @{$cnt{$1}},($2,$3) for @stuff; @$_ = sort { $a <=> $b } @$_ for values %cnt; my ($hi_from, $hi_to, $bye_from, $bye_to); # if we *know* what to exp +ect while( my ($k,$v) = each %cnt ) { my @evil_plan = ( "\$${k}_from=$$v[0]", "\$${k}_to=$$v[-1]" ); print join(' and ', @evil_plan), "\n"; # show what we prepared map eval, @evil_plan; # execute the unthinkable } print "\n$hi_from, $hi_to \n$bye_from, $bye_to\n"; # control

Regards

mwa