# AliceUtils.pm package AliceUtils; sub safe_filename { my $string = shift; $string =~ s{\W}{}g; $string = "untitled" if !$string; return $string; } 1; # BobUtils.pm package BobUtils; use AliceUtils; # Make sure it's loaded! sub save_data { my ( $filename, $data ) = @_; my $safe_filename = AliceUtils::safe_filename( $filename ) . ".txt"; open my $fh, '>', $safe_filename or die; print $fh $data or die; close $fh or die; return $safe_filename; } 1; # example.pl use AliceUtils; use BobUtils; BobUtils::save_data( "my file", "Hello world!\n" );