my $test = qq| sdfiojs pfojsdfs fs [img]sdj fpsdofj spojf sfsf [b] [img]http://www.test.com/image.gif[/img] dfs fs s fsf sfd [img]test.gif[/img] |; while ($test =~ /\[img\](.+?)\[\/img\]/g) { print "$1 \n"; } #### C:\Users\Andy>perl test.pl sdj fpsdofj spojf sfsf [b] [img]http://www.test.com/image.gi test.gif #### C:\Users\Andy>perl test.pl http://www.test.com/image.gif test.gif