#!perl my $text = "test1 zzzzzzzzzzzzzzz test2 test3 test4 test5 zzzzzzzzzzzzzzz test6 test7 zzzzzzzzzzzzzzz test8 test9 test10"; # search for a-z0-9_ followed by whitespace then zzzzzzzzz then whitespace then a-z0-9_ if ( $text =~ /([a-zA-Z0-9]+\s+[z]{15}\s+[a-z0-9]+)/ ) { print "string \$1: " . $1 . "!\n"; print "string \$2: " . $2 . "!\n"; } else { print "string not found...!\n"; } print "text is " . $text . "\n";