#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $str =" abc xyz \n"; my @tokens = split(/\s+/,$str); print Dumper \@tokens; =PRINTS: $VAR1 = [ '', 'abc', 'xyz' ]; =cut @tokens = split (' ',$str); print Dumper \@tokens; # note: leading blank field is not there! # no need to remove spaces at beginning or end of # line with this special situation. =PRINTS: $VAR1 = [ 'abc', 'xyz' ]; =cut