#!/usr/bin/perl -wT use strict; my $text = "my text [and maybe|and here's] more text [the end|stop]"; my @arr = parseit($text); print "$_\n" for @arr; sub parseit { my $text = shift; for ($text) { s/\[/{/g; s/\]/}/g; s/\|/,/g; } glob($text); } __END__ my text and maybe more text the end my text and maybe more text stop my text and here's more text the end my text and here's more text stop