use strict; my $input = "[http://forum1.reith.bbc.co.uk/cgi-perl/h2/h2.cgi|title]"; my $nasty_input = "[http://\nforum1.\nreith.bbc.co.uk/cgi-perl\n/h2/h2.cgi|title]"; my $garbage = "blahblabhladas sdfgsdgf.\ndsfg\n\t\tsdfxsdf\n\tasf"; my $poo = join('', reverse( split(//, $garbage) )); my $final_input = $nasty_input . $garbage . $input . $poo . $garbage . $poo . $input . $garbage . $nasty_input; print $final_input,"\n"; # This assumes that the delimiters surround our urls. # The next step would be to pass $string to something like URI to test if it # is a valid url. Either that or to URI::Find to see if there is a sub url in there. # Though I think URI::Find wouldn't like the |title stuff on the end. while($final_input =~ /\[(.*?)\]/sgc) { my $string = $1; if($string =~ /\n\r?/sg) { $string =~ s/\n\r?//sg; } print $string,"\n"; }