#!/usr/bin/perl5 -w use strict; my ($is_okay, $value); sub return_okay { my $test_string = shift; my $private_result = ($test_string =~ /myregex/); return ($private_result); } sub return_okay2 { # concise version return ($_[0] =~ /myregex/); } sub modify_okay { # but see WARNING below # Called as: modify_okay($string, $result_flag) $_[1] = ($_[0] =~ /myregex/); } my @vals = qw(abcdefg myregex tuvwxyz); print "Using a return value:\n"; foreach $value (@vals) { $is_okay = return_okay2($value); ### if ($is_okay) { print "$value is okay.\n"; } else { print "$value is not okay.\n"; } } print "\nUsing a modified value:\n"; foreach $value (@vals) { modify_okay($value, $is_okay); ### if ($is_okay) { print "$value is okay.\n"; } else { print "$value is not okay.\n"; } } # WARNING: the modify method can blow up on you # Notice that the following line causes a fatal error # because of the attempt to modify a constant: modify_okay("some string", 1); print "And this never prints\n";