use strict; use warnings; my @a = qw! / /home /var /tmp /var/tmp !; my @b = map [ m!/$! ? <$_*> : <$_/*> ], @a; print map "$_\n\n", @$_ for @b;