$ perl -MO=Deparse -ane '$s = ""; foreach (@F) { /(\d+)-(\d+)/ and $2 - $1 >= 30 and $s .= " $1-$2" } print "$F[0]$s\n" if $s' LINE: while (defined($_ = )) { our @F = split(' ', $_, 0); $s = ''; foreach $_ (@F) { $s .= " $1-$2" if /(\d+)-(\d+)/ and $2 - $1 >= 30; } print "$F[0]$s\n" if $s; }