#!/usr/bin/perl use warnings; use strict; use Data::Dumper; my %options; my $current_option; my $space; for (@ARGV) { if (/^-/) { $current_option = $_; $space = q(); # No space before the first word. } else { $options{$current_option} .= $space . $_; $space = ' '; } } print Dumper \%options;