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