while (my $line = ) { if ($line =~ /(-?\$\d*\.\d*)/) { print OUTFILE $1, "\n"; } else { # Amount not found... } }