#!/usr/bin/perl chomp; my @refs = /((the|a) (big( red)?|small( yellow)?) (car|bike))/; next unless (@refs > 0); print "\"$_\"\n"; for ($i = 1; @refs > 0; $i++) { my $ref = shift @refs; printf "\\$i => %s\n", (defined $ref) ? $ref : "(null)"; } print "\n";