my $target = shift || 'word'; $target = qr/$target/; my $re = qr/a=<([^>]+)>/; while( ) { next unless /$re/; my $s = $1; print "[$s]\n" if $s =~ /$target/; }