# function definition def do_thing(name, country): print("Person's name: {}, country: {}\n".format(name, country)) # scoping a file operation with open("file.txt") as fh: # in file scope for line in fh.readlines(): # in for scope print(line) # file handle is now closed automatically #### # function sub do_thing { my ($name, $country) = @_; print "Person's name: $name, country: $country\n"; } # file { # file handle is scoped to this block open my $fh, '<', 'file.txt' or die $!; while (my $line = <$fh>){ # we're now in a lower-level scope print "$line\n"; } } # file handle is closed and unavailable here