#!/usr/bin/perl -w use strict; my $string = " abc xyz"; my @tokens = split(' ',$string); print "There are ".@tokens." tokens in \'$string\'\n"; print "Using split on ' '\n"; print join("|",@tokens),"\n\n"; my @tokens2 = split(/\s+/,$string); print "There are ".@tokens2." tokens in \'$string\'\n"; print "Using split on /\\s+/\n"; print join("|",@tokens2),"\n\n"; my @tokens3 = split(/ /,$string); print "There are ".@tokens3." tokens in \'$string\'\n"; print "Using split on / /\n"; print join("|",@tokens3),"\n\n"; my @tokens4 = split(/\s/,$string); print "There are ".@tokens4." tokens in \'$string\'\n"; print "Using split on /\\s/\n"; print join("|",@tokens4),"\n"; __END__ The above code prints: There are 2 tokens in ' abc xyz' Using split on ' ' abc|xyz There are 3 tokens in ' abc xyz' Using split on /\s+/ |abc|xyz There are 6 tokens in ' abc xyz' Using split on / / ||||abc|xyz There are 6 tokens in ' abc xyz' Using split on /\s/ ||||abc|xyz