#! perl -slw use strict; local $/= "\n====\n"; while( ) { ## Clear out residual values from global vars our( $no1, $no2, $price ) = ( undef ) x 3; tr[\n][ ]; ## Strip newlines ## Extract the cash value into $price s[ ( \$[\d,]+ (?:\.\d+)? ) (?{ $price = $^N }) ][ ]x; ## Grab the first 1 or 2 telephone numbers s[ ( [\d-]{12} ) (?{ $no1 ? $no2 = $^N : $no1 = $^N }) ][ ]xg; ## join them together in the requisite order and output print join ', ', $no1||'n/a', $no2||'n/a', $price||'n/a', $_; }