sub explode($$;$) { my ($separator,$string,$limit) = @_; my @splitted; my $x = 1; my $offset = 0; my $sep_len = length($separator); while((my $pos = index($string,$separator,$offset)) >= 0 && (!$limit || $x < $limit)) { my $part = substr($string,$offset,$pos-$offset); push(@splitted,$part); $offset = $pos+$sep_len; $x++; } push(@splitted,substr($string,$offset,length($string)-$offset)); return @splitted; }