use strict; use warnings; my $sel = 'SELECT f1 AS x1,f2,f3,f4 as x2, (f4= f5) as x3 FROM'; $sel =~ /SELECT\s+(.*?)FROM/i or die "Select clause not found in: $sel"; my @parts = map {/(\w+)\s*$/; $1} split /\s*,\s*/, $1; print "SELECT ", join (', ', @parts), " FROM\n"; #### SELECT x1, f2, f3, x2, x3 FROM