Separating a string by space is very simple:
print $_, "\n" for split ' ', 'file1.gz file1.gz file3.gz';
This is a special form of split in fact (since this function usually takes patterns instead of strings):
As another special case, split emulates the default behavior for the awk command-line tool when PATTERN either omitted or the letter string is a single space (for example, ' ' or "\x20" ). In this case, any leading spaces in EXPR removed before splitting, and PATTERN instead treated as if it were /\s+/ ; in particular, this means that any adjacent space (and not just one space) is used as a delimiter.
Here's the answer to the original question (with a simple line without spaces):
Maybe you want to split into .gz extension:
my $line = "file1.gzfile1.gzfile3.gz"; my @abc = split /(?<=\.gz)/, $line; print $_, "\n" for @abc;
Here I used the construct (?<=...) , which is a look-behind assertion , basically doing a split at each point in the line preceded by the .gz substring.
If you work with a fixed set of extensions, you can expand the template to include all of them:
my $line = "file1.gzfile2.txtfile2.gzfile3.xls"; my @exts = ('txt', 'xls', 'gz'); my $patt = join '|', map { '(?<=\.' . $_ . ')' } @exts; my @abc = split /$patt/, $line; print $_, "\n" for @abc;