                Example 2

#!/bin/perl
# swap.pl
#
# perl: swap first two fields in a line of tab-delimited fields
#
# Run this program with the command
#
#   perl swap.pl swap.txt
#
# where swap.txt is an input file with tab-delimited fields

while (<>)  {
    s/^([^\t]*)\t([^\t\n]*)/$2\t$1/;
    print "$_"
}
