sub test_match { my( $regexp, $string ) = @_; return scalar( $string =~ $regexp ); } my $string = "Hello world!\n"; print $string if test_match( qr/hello/i, $string );