use warnings; use strict; $0 =~ '(.*[\\\/])\w+\.\w+$'; my $curr_dir = $1 || "./"; # Note, you would be much better off with # use Cwd; # and # my $curr_dir = cwd(); $info_file = $curr_dir . '../htdocs/info.txt'; open my $fh, '<', $info_file or die "Could not open file, $!"; while (my $line = <$fh>){ #process line }