package whatever; ... @EXPORT = qw( $routine ); $routine = q^ $thing = something+something_else; lots and lots of code; ^; sub routine [ my ($thing, $other_thing) = @_; eval $routine; } package main; my $thing; my $other_thing; eval $routine;