while ($data_in =~ /(.+?)<\/a>(.+?)<\/b><\/container>(<\?query\?>)??/ig) { if ($+ =~ /<\?query\?>/i) {; errors here now $data_out = "$2, $1$3 "; } else { $data_out = "$2, $1 "; } ; further processing here }