#!/usr/bin/perl -w use strict; my $line = "this- is-aline - one- two "; my @array = split (/-/,$line); foreach (@array) { s/\s+$//g; #throw away tailing whitespace s/^\s+//g; #throw away leading whitespace print "$_\n"; } __END__ PRINTS: this is aline one two