#!/usr/bin/perl

use Text::ParseWords;

@words = shellwords( "echo 'foo bar'" );
# $words[0] is now q(echo) and $words[1] q(foo bar).

@words = quotewords( '\s+', 1, 'echo "foo $bar"' );
# $words[0] is now 'echo' and $words[1] '"foo $bar"'.

print "The first word is $words[0] and the second word is $words[1].\n";